#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int unsigned
using namespace std;
int n;
int v[200003],c[200003],x[200003],s[200003];
const int mod = 998244353;
long long f[2][2001*2001];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	cin >> n;
	int mx = n;
	for(int i = 1;i <= n;i++)
		cin >> v[i],mx = max(mx,v[i]);
	for(int i = 1;i <= n;i++)
		cin >> c[i],mx = max(mx,c[i]);
	bool flagA = 1,flagB = 1;
	for(int i = 1;i < n;i++)
		cin >> x[i],flagA &= (x[i] == 1000000000),flagB &= (x[i] == 1);
	for(int i = 1;i < n;i++) if(v[i] == 0)
		c[i + 1] += c[i] / x[i],c[i] %= x[i];
	if(flagA)
	{
		long long ans = 0;
		for(int i = 1;i <= n;i++)
			ans += 1ll * c[i] * v[i] % mod;
		cout << ans % mod;
		return 0;
	}
	if(flagB)
	{
		long long ans = 0;
		for(int i = n,mx = v[i];i;mx = max(mx,v[--i]))
			ans += 1ll * c[i] * mx % mod;
		cout << ans % mod;
		return 0;
	}
	for(int i = 1;i <= n;i++)
		s[i] = s[i - 1] + c[i];
	x[n] = 1;
	if(mx <= 2000)
	{
		int nw = 0,lst = 1;
		for(int i = n;i;i--)
		{
			swap(nw,lst);
			int U = s[i],d = x[i],w = v[i];
			f[nw][0] = 0;
			for(int k = 0,l = c[i + 1],r;k <= U;k = r,l++)
			{
				f[nw][k] = max(f[nw][k],f[lst][l]);
				r = min(k + d,U + 1);
				for(int j = k;j < r;j++)
					f[nw][j + 1] = f[nw][j] + w;
			}
		}
		cout << f[nw][c[1]] % mod;
		return 0;
	}
	for(int i = 1;i < n;i++)
		if(1ll * v[i] * x[i] < v[i + 1])
			c[i + 1] += c[i] / x[i],c[i] %= x[i];
	long long ans = 0;
	for(int i = 1;i <= n;i++)
		ans += 1ll * c[i] * v[i] % mod;
	cout << ans % mod;
	return 0;
}